<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="_csrf" th:content="${_csrf.token}" />
<meta name="_csrf_header" th:content="${_csrf.headerName}" />
<link th:href="@{/static/bootstrap/css/bootstrap.min.css}"
	rel="stylesheet">
<link rel="stylesheet"
	th:href="@{/static/jquery-file-upload/css/jquery.fileupload.css}">
<link rel="stylesheet" th:href="@{/static/css/sb-admin-2.css}">
<link th:href="@{/static/css/blog.css}" rel="stylesheet">
<link th:href="@{/static/summernote/dist/summernote.css}"
	rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
	  <script th:src="@{/static/js/html5shiv.min.js}"></script>
	  <script th:src="@{/static/js/respond.min.js}"></script>
	<![endif]-->
<title>动态</title>
<style>
.media-body img {
	display: block;
	max-width: 100%;
	height: auto;
}
</style>
</head>
<body>
	<nav th:replace="mgr/base/nav :: active('news')"></nav>
	<div id="page-wrapper" style="padding: 10px">
		<div class="container-fluid">
			<div class="row">
				<div class="col-md-8 col-md-offset-2">
					<a class="btn btn-primary" th:href="@{/mgr/news/index}">返回</a>
				</div>
			</div>
			<div class="row" style="margin-top: 10px">
				<div class="col-md-8 col-md-offset-2">
					<form>
						<div class="form-group">
							<label>时间</label> <input type="text" class="form-control"
								id="time"
								th:if="${news.write != null}"
								th:value="${times.format(news.write,'yyyy-MM-dd HH:mm:ss')}" />
								<input type="text" class="form-control"
								id="time"
								th:if="${news.write == null}" th:value="${times.format(times.now(),'yyyy-MM-dd HH:mm')}"/>
						</div>
						<div class="form-group">
							<label>内容</label>
							<textarea class="form-control summernote" id="content">[[${news.content}]]</textarea>
						</div>
						<div class="checkbox">
						    <label>
						      <input id="private" type="checkbox" th:attr="checked=${news.isPrivate !=null && news.isPrivate ? 'checked' : null}"> 私人
						    </label>
						  </div>
						  <div class="checkbox">
						    <label>
						      <input id="allowComment" type="checkbox" th:attr="checked=${news.allowComment == null ? 'checked' : (news.allowComment != null  && news.allowComment  ? 'checked' : null)}"> 允许评论
						    </label>
						  </div>
						<button type="button" id="edit-btn" class="btn btn-default">提交</button>
					</form>
				</div>
			</div>
		</div>
	</div>
	<input type="hidden" th:value="${news.id}" id="id" />
	<div th:replace="base/foot_source"></div>
	<script type="text/javascript" th:src="@{/static/js/mgr/common.js}"></script>
		<script type="text/javascript"
		th:src="@{/static/jquery-file-upload/js/load-image.min.js}"></script>
	<script type="text/javascript"
		th:src="@{/static/js/canvas-to-blob.min.js}"></script>
	<script
		th:src="@{/static/jquery-file-upload/js/vendor/jquery.ui.widget.js}"></script>
	<script
		th:src="@{/static/jquery-file-upload/js/jquery.iframe-transport.js}"></script>
	<script th:src="@{/static/jquery-file-upload/js/jquery.fileupload.js}"></script>
	<script
		th:src="@{/static/jquery-file-upload/js/jquery.fileupload-ui.js}"></script>
	<script
		th:src="@{/static/jquery-file-upload/js/jquery.fileupload-process.js}"></script>
	<script
		th:src="@{/static/jquery-file-upload/js/jquery.fileupload-image.js}"></script>
	<script
		th:src="@{/static/jquery-file-upload/js/jquery.fileupload-audio.js}"></script>
	<script
		th:src="@{/static/jquery-file-upload/js/jquery.fileupload-video.js}"></script>
	<script
		th:src="@{/static/jquery-file-upload/js/jquery.fileupload-validate.js}"></script>
	<script type="text/javascript"
		th:src="@{/static/summernote/dist/summernote.min.js}"></script>
	<script type="text/javascript"
		th:src="@{/static/summernote/dist/lang/summernote-zh-CN.min.js}"></script>
	<script type="text/javascript"
		th:src="@{/static/summernote/plugin/file/summernote-ext-file.js}"></script>
	<script type="text/javascript"
		th:src="@{/static/summernote/plugin/file/file.js}"></script>
	<script>
		$(function(){
			$('#content').summernote({
				lang: 'zh-CN',
				height:270,
				focus:true,
				toolbar:[
					['custom', ['file']],
					['style', ['style']],
		            ['font', ['bold', 'underline', 'clear']],
		            ['fontname', ['fontname']],
		            ['color', ['color']],
		            ['para', ['ul', 'ol', 'paragraph']],
		            ['insert', ['link', 'video']],
		            ['view', ['fullscreen', 'codeview']]
				]
			});
			
			$("#edit-btn").click(function(){
				var me = $(this);
				var content = $("#content").summernote('code');
				var news = {};
				var id = $("#id").val();
				var edit = id && id != '';
				var url = edit ? basePath + '/mgr/news/update' : basePath + '/mgr/news/write';
				news.content = content;
				if(edit)
					news.id = id;
				news.write = $("#time").val();
				news.allowComment = $("#allowComment").is(":checked");
				news.isPrivate = $("#private").is(":checked");
				$.ajax({
					type : "post",
					url : url,
		            contentType:"application/json",
					data : JSON.stringify(news),
					success : function(data){
						if(data.success){
							bootbox.alert("保存成功");
							setTimeout(function(){
								if(edit)
									window.location.reload();
								else
									window.location.href = basePath +'/mgr/news/index';
							},500)
						} else {
							bootbox.alert(data.message);
						}
					},
					complete:function(){
						me.prop("disabled",false);
					}
				});
			});
		});
		</script>
</body>
</html>